package com.stp.event.controller;

import com.stp.event.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @GetMapping("/send")
    public String send(@RequestParam("type")String type){
        PayEventModel payEvent = null;
        switch (type){
            case "aliPay":
                payEvent = new AliPayEventEntity().setModel("aliPay").setPayInfo(new AliPayEntity().setAppId("ali"));
                break;
            case "wxPay":
                payEvent = new WxPayEventEntity().setModel("wxPay").setPayInfo(new WxPayEntity().setAppId("wx"));
                break;
        }

        PayApplicationEvent event = new PayApplicationEvent(this,payEvent);
        applicationEventPublisher.publishEvent(event);
        return type;
    }
}
